package m2_work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.126.129");
        f.setUsername("admin");
        f.setPassword("admin");

        Channel channel = f.newConnection().createChannel();

        //定义队列   --durable:true 持久队列
        channel.queueDeclare("task_queue",true,false,false,null);

        //发消息
        while (true){
            System.out.println("输入消息:");
            String msg = new Scanner(System.in).nextLine();
            //MessageProperties.PERSISTENT_TEXT_PLAIN  持久化文件
            channel.basicPublish("","task_queue", MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes());
        }

    }
}
